Skip to main content

Users

note you can use v chat test server base url is http://170.178.195.150:81/api/v1/

  • First you need to read this tab to know how v chat works
  • also, you need to read this tab to know how public apis works

1 - Register

  • URL: {{baseUrl}}user/register
  • Method: POST
  • Authentication: No access token required
  • Content-Type: form-data to send image of user in file parameter
  • Example request data:
{
"email":"example@exmaple.com",
"name": "name",
"password":"hashedPassword",
"file":"image from mutil part"
"fcmToken":"user fcm token or playerId for onsignal"
}
ParameterRequiredDescription
emailtrueuser email
nametrueuser name
passwordtrueuser hashed password see how to get it
filefalseuser image if null will user default image
fcmTokentruefcmToken for notifications if not exist pass it Out
  • to get hashedPassword you need to the following
  1. import crypto-js or any model that can create SHA512
  2. import utf8 to encode this string
  3. ${process.env.PASSWORD_HASH_KEY}_$email}
  4. full code in node js is cryptoJs.SHA512(utf8.encode(`${process.env.PASSWORD_HASH_KEY}_${user['email']}`)).toString(),
  5. PASSWORD_HASH_KEY is string you set it in .env file in backend code it must be same in front and backend
  6. if you skip this step user will success register but when he wants to log in again he cant

Example response:

{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxY2Q4ZmIzM2JkODczMWJlMDQwZTEwMyIsImlhdCI6MTY0MDg2MTYxOSwiZXhwIjoxODY3ODgwODYxNjE5fQ.XfR7_-kNptfMyXopiPYgLTojhpI7oRUsK9g06Nc0kBY"
}
}

2 - Login

  • URL: {{baseUrl}}user/login
  • Method: POST
  • Content-Type: JSON
  • Authentication: No access token required
  • Example request data:
{
"email": "user1",
"password": "user1",
"fcmToken": "fcm token"
}
ParameterRequiredDescription
emailtrueuser email
passwordtrueuser password
fcmTokentruefcm token if not exist pass it Out
  • to get hashedPassword you need to the following
  1. import crypto-js or any model that can create SHA512
  2. import utf8 to encode this string
  3. ${process.env.PASSWORD_HASH_KEY}_$email}
  4. full code in node js is cryptoJs.SHA512(utf8.encode(`${process.env.PASSWORD_HASH_KEY}_${user['email']}`)).toString(),
  5. PASSWORD_HASH_KEY is string you set it in .env file in backend code it must be same in front and backend
  6. if you skip this step user will success register but when he wants to log in again he cant Example response:
{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYxY2Q4ZmIzM2JkODczMWJlMDQwZTEwMyIsImlhdCI6MTY0MDg2MTYxOSwiZXhwIjoxODY3ODgwODYxNjE5fQ.XfR7_-kNptfMyXopiPYgLTojhpI7oRUsK9g06Nc0kBY"
}
}

3 - Update

  • URL: {{baseUrl}}user
  • Method: PATCH
  • Authentication: Bearer token is required in header in authorization : Bearer yourToken
  • Content-Type: form-data to send image of user in file parameter
  • Example request data:
{ 
"name": "name",
"file":"image from mutil part"
"fcmToken":"user fcm token or playerId for onsignal"
}
ParameterRequiredDescription
namefalseuser name
filefalseuser image if null will user default image
fcmTokenfalsefcmToken for notifications if not exist pass it Out
  • if any parameter above send then the update will be done on it other will ignore

Example response:

{
"success": true,
"data": {
"_id": "61cd8fb33bd8731be040e103",
"imageThumb": "default_user_image.png",
"createdAt": 1640861592248,
"updatedAt": 1640861592248,
"email": "user1",
"name": "user1 updated name"
}
}